
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>4-12 按需加载 · 深入浅出 Webpack</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="吴浩麟">
        <meta name="identifier" content="9787121331725" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-modal/index.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        

    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4-13使用Prepack.html" />
    
    
    <link rel="prev" href="4-11提取公共代码.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"gwuhaolin","type":"follow","size":"small","width":"150"},{"user":"gwuhaolin","repo":"dive-into-webpack","type":"star","size":"small"}]};
    </script>


    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
  
  

  

  
  
  

<li class="chapter " data-level="1.1" data-path="../">
  
  <a href="../">
    
                    
                    深入浅出 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.2" data-path="../前言.html">
  
  <a href="../前言.html">
    
                    
                    前言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3" data-path="../1入门/">
  
  <a href="../1入门/">
    
                    
                    第1章 入门
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.3.1" data-path="../1入门/1-1前端的发展.html">
  
  <a href="../1入门/1-1前端的发展.html">
    
                    
                    1-1 前端的发展
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.2" data-path="../1入门/1-2常见的构建工具及对比.html">
  
  <a href="../1入门/1-2常见的构建工具及对比.html">
    
                    
                    1-2 常见的构建工具及对比
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.3" data-path="../1入门/1-3安装与使用.html">
  
  <a href="../1入门/1-3安装与使用.html">
    
                    
                    1-3 安装与使用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.4" data-path="../1入门/1-4使用Loader.html">
  
  <a href="../1入门/1-4使用Loader.html">
    
                    
                    1-4 使用 Loader
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.5" data-path="../1入门/1-5使用Plugin.html">
  
  <a href="../1入门/1-5使用Plugin.html">
    
                    
                    1-5 使用 Plugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.6" data-path="../1入门/1-6使用DevServer.html">
  
  <a href="../1入门/1-6使用DevServer.html">
    
                    
                    1-6 使用 DevServer
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.7" data-path="../1入门/1-7核心概念.html">
  
  <a href="../1入门/1-7核心概念.html">
    
                    
                    1-7 核心概念
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.4" data-path="../2配置/">
  
  <a href="../2配置/">
    
                    
                    第2章 配置
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.4.1" data-path="../2配置/2-1Entry.html">
  
  <a href="../2配置/2-1Entry.html">
    
                    
                    2-1 Entry
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.2" data-path="../2配置/2-2Output.html">
  
  <a href="../2配置/2-2Output.html">
    
                    
                    2-2 Output
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.3" data-path="../2配置/2-3Module.html">
  
  <a href="../2配置/2-3Module.html">
    
                    
                    2-3 Module
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.4" data-path="../2配置/2-4Resolve.html">
  
  <a href="../2配置/2-4Resolve.html">
    
                    
                    2-4 Resolve
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.5" data-path="../2配置/2-5Plugins.html">
  
  <a href="../2配置/2-5Plugins.html">
    
                    
                    2-5 Plugins
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.6" data-path="../2配置/2-6DevServer.html">
  
  <a href="../2配置/2-6DevServer.html">
    
                    
                    2-6 DevServer
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.7" data-path="../2配置/2-7其它配置项.html">
  
  <a href="../2配置/2-7其它配置项.html">
    
                    
                    2-7 其它配置项
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.8" data-path="../2配置/2-8整体配置结构.html">
  
  <a href="../2配置/2-8整体配置结构.html">
    
                    
                    2-8 整体配置结构
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.9" data-path="../2配置/2-9多种配置类型.html">
  
  <a href="../2配置/2-9多种配置类型.html">
    
                    
                    2-9 多种配置类型
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.10" data-path="../2配置/2-10配置总结.html">
  
  <a href="../2配置/2-10配置总结.html">
    
                    
                    2-10 配置总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.5" data-path="../3实战/">
  
  <a href="../3实战/">
    
                    
                    第3章 实战
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.5.1" data-path="../3实战/3-1使用ES6语言.html">
  
  <a href="../3实战/3-1使用ES6语言.html">
    
                    
                    3-1 使用 ES6 语言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.2" data-path="../3实战/3-2使用TypeScript语言.html">
  
  <a href="../3实战/3-2使用TypeScript语言.html">
    
                    
                    3-2 使用 TypeScript 语言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.3" data-path="../3实战/3-3使用Flow检查器.html">
  
  <a href="../3实战/3-3使用Flow检查器.html">
    
                    
                    3-3 使用 Flow 检查器
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.4" data-path="../3实战/3-4使用SCSS语言.html">
  
  <a href="../3实战/3-4使用SCSS语言.html">
    
                    
                    3-4 使用 SCSS
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.5" data-path="../3实战/3-5使用PostCSS.html">
  
  <a href="../3实战/3-5使用PostCSS.html">
    
                    
                    3-5 使用 PostCSS
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.6" data-path="../3实战/3-6使用React框架.html">
  
  <a href="../3实战/3-6使用React框架.html">
    
                    
                    3-6 使用 React 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.7" data-path="../3实战/3-7使用Vue框架.html">
  
  <a href="../3实战/3-7使用Vue框架.html">
    
                    
                    3-7 使用 Vue 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.8" data-path="../3实战/3-8使用Angular2框架.html">
  
  <a href="../3实战/3-8使用Angular2框架.html">
    
                    
                    3-8 使用 Angular2 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.9" data-path="../3实战/3-9为单页应用生成HTML.html">
  
  <a href="../3实战/3-9为单页应用生成HTML.html">
    
                    
                    3-9 为单页应用生成 HTML
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.10" data-path="../3实战/3-10管理多个单页应用.html">
  
  <a href="../3实战/3-10管理多个单页应用.html">
    
                    
                    3-10 管理多个单页应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.11" data-path="../3实战/3-11构建同构应用.html">
  
  <a href="../3实战/3-11构建同构应用.html">
    
                    
                    3-11 构建同构应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.12" data-path="../3实战/3-12构建Electron应用.html">
  
  <a href="../3实战/3-12构建Electron应用.html">
    
                    
                    3-12 构建 Electron 应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.13" data-path="../3实战/3-13构建Npm模块.html">
  
  <a href="../3实战/3-13构建Npm模块.html">
    
                    
                    3-13 构建 Npm 模块
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.14" data-path="../3实战/3-14构建离线应用.html">
  
  <a href="../3实战/3-14构建离线应用.html">
    
                    
                    3-14 构建离线应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.15" data-path="../3实战/3-15搭配NpmScript.html">
  
  <a href="../3实战/3-15搭配NpmScript.html">
    
                    
                    3-15 搭配 Npm Script
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.16" data-path="../3实战/3-16检查代码.html">
  
  <a href="../3实战/3-16检查代码.html">
    
                    
                    3-16 检查代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.17" data-path="../3实战/3-17通过Node.jsAPI启动Webpack.html">
  
  <a href="../3实战/3-17通过Node.jsAPI启动Webpack.html">
    
                    
                    3-17 通过 Node.js API 启动 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.18" data-path="../3实战/3-18使用WebpackDevMiddleware.html">
  
  <a href="../3实战/3-18使用WebpackDevMiddleware.html">
    
                    
                    3-18 使用 Webpack Dev Middleware
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.19" data-path="../3实战/3-19加载图片.html">
  
  <a href="../3实战/3-19加载图片.html">
    
                    
                    3-19 加载图片
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.20" data-path="../3实战/3-20加载SVG.html">
  
  <a href="../3实战/3-20加载SVG.html">
    
                    
                    3-20 加载SVG
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.21" data-path="../3实战/3-21加载SourceMap.html">
  
  <a href="../3实战/3-21加载SourceMap.html">
    
                    
                    3-21 加载 Source Map
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.22" data-path="../3实战/3-22实战总结.html">
  
  <a href="../3实战/3-22实战总结.html">
    
                    
                    3-22 实战总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.6" data-path="./">
  
  <a href="./">
    
                    
                    第4章 优化
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.6.1" data-path="4-1缩小文件搜索范围.html">
  
  <a href="4-1缩小文件搜索范围.html">
    
                    
                    4-1 缩小文件搜索范围
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.2" data-path="4-2使用DllPlugin.html">
  
  <a href="4-2使用DllPlugin.html">
    
                    
                    4-2 使用 DllPlugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.3" data-path="4-3使用HappyPack.html">
  
  <a href="4-3使用HappyPack.html">
    
                    
                    4-3 使用 HappyPack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.4" data-path="4-4使用ParallelUglifyPlugin.html">
  
  <a href="4-4使用ParallelUglifyPlugin.html">
    
                    
                    4-4 使用 ParallelUglifyPlugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.5" data-path="4-5使用自动刷新.html">
  
  <a href="4-5使用自动刷新.html">
    
                    
                    4-5 使用自动刷新
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.6" data-path="4-6开启模块热替换.html">
  
  <a href="4-6开启模块热替换.html">
    
                    
                    4-6 开启模块热替换
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.7" data-path="4-7区分环境.html">
  
  <a href="4-7区分环境.html">
    
                    
                    4-7 区分环境
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.8" data-path="4-8压缩代码.html">
  
  <a href="4-8压缩代码.html">
    
                    
                    4-8 压缩代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.9" data-path="4-9CDN加速.html">
  
  <a href="4-9CDN加速.html">
    
                    
                    4-9 CDN 加速
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.10" data-path="4-10使用TreeShaking.html">
  
  <a href="4-10使用TreeShaking.html">
    
                    
                    4-10 使用 Tree Shaking
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.11" data-path="4-11提取公共代码.html">
  
  <a href="4-11提取公共代码.html">
    
                    
                    4-11 提取公共代码
            
    </a>
    

    
</li>

<li class="chapter active" data-level="1.6.12" data-path="4-12按需加载.html">
  
  <a href="4-12按需加载.html">
    
                    
                    4-12 按需加载
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.13" data-path="4-13使用Prepack.html">
  
  <a href="4-13使用Prepack.html">
    
                    
                    4-13 使用 Prepack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.14" data-path="4-14开启ScopeHoisting.html">
  
  <a href="4-14开启ScopeHoisting.html">
    
                    
                    4-14 开启 Scope Hoisting
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.15" data-path="4-15输出分析.html">
  
  <a href="4-15输出分析.html">
    
                    
                    4-15 输出分析
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.16" data-path="4-16优化总结.html">
  
  <a href="4-16优化总结.html">
    
                    
                    4-16 优化总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.7" data-path="../5原理/">
  
  <a href="../5原理/">
    
                    
                    第5章 原理
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.7.1" data-path="../5原理/5-1工作原理概括.html">
  
  <a href="../5原理/5-1工作原理概括.html">
    
                    
                    5-1 工作原理概括
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.2" data-path="../5原理/5-2输出文件分析.html">
  
  <a href="../5原理/5-2输出文件分析.html">
    
                    
                    5-2 输出文件分析
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.3" data-path="../5原理/5-3编写Loader.html">
  
  <a href="../5原理/5-3编写Loader.html">
    
                    
                    5-3 编写 Loader
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.4" data-path="../5原理/5-4编写Plugin.html">
  
  <a href="../5原理/5-4编写Plugin.html">
    
                    
                    5-4 编写 Plugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.5" data-path="../5原理/5-5调试Webpack.html">
  
  <a href="../5原理/5-5调试Webpack.html">
    
                    
                    5-5 调试 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.6" data-path="../5原理/5-6原理总结.html">
  
  <a href="../5原理/5-6原理总结.html">
    
                    
                    5-6 原理总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.8" >
  
      <span>
            
                    
                    附录
            
    </span>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.8.1" data-path="../附录/常用Loaders.html">
  
  <a href="../附录/常用Loaders.html">
    
                    
                    常用 Loaders
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.8.2" data-path="../附录/常用Plugins.html">
  
  <a href="../附录/常用Plugins.html">
    
                    
                    常用 Plugins
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.8.3" data-path="../附录/其它Webpack学习资源.html">
  
  <a href="../附录/其它Webpack学习资源.html">
    
                    
                    其它 Webpack 学习资源
            
    </a>
    

    
</li>


    </ul>
    
</li>


  

  <li class="divider"></li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >4-12 按需加载</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="4-12-&#x5206;&#x5272;&#x4EE3;&#x7801;&#x6309;&#x9700;&#x52A0;&#x8F7D;">4-12 &#x5206;&#x5272;&#x4EE3;&#x7801;&#x6309;&#x9700;&#x52A0;&#x8F7D;</h1>
<h2 id="&#x4E3A;&#x4EC0;&#x4E48;&#x9700;&#x8981;&#x6309;&#x9700;&#x52A0;&#x8F7D;">&#x4E3A;&#x4EC0;&#x4E48;&#x9700;&#x8981;&#x6309;&#x9700;&#x52A0;&#x8F7D;</h2>
<p>&#x968F;&#x7740;&#x4E92;&#x8054;&#x7F51;&#x7684;&#x53D1;&#x5C55;&#xFF0C;&#x4E00;&#x4E2A;&#x7F51;&#x9875;&#x9700;&#x8981;&#x627F;&#x8F7D;&#x7684;&#x529F;&#x80FD;&#x8D8A;&#x6765;&#x8D8A;&#x591A;&#x3002;
&#x5BF9;&#x4E8E;&#x91C7;&#x7528;&#x5355;&#x9875;&#x5E94;&#x7528;&#x4F5C;&#x4E3A;&#x524D;&#x7AEF;&#x67B6;&#x6784;&#x7684;&#x7F51;&#x7AD9;&#x6765;&#x8BF4;&#xFF0C;&#x4F1A;&#x9762;&#x4E34;&#x7740;&#x4E00;&#x4E2A;&#x7F51;&#x9875;&#x9700;&#x8981;&#x52A0;&#x8F7D;&#x7684;&#x4EE3;&#x7801;&#x91CF;&#x5F88;&#x5927;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x56E0;&#x4E3A;&#x8BB8;&#x591A;&#x529F;&#x80FD;&#x90FD;&#x96C6;&#x4E2D;&#x7684;&#x505A;&#x5230;&#x4E86;&#x4E00;&#x4E2A; HTML &#x91CC;&#x3002;
&#x8FD9;&#x4F1A;&#x5BFC;&#x81F4;&#x7F51;&#x9875;&#x52A0;&#x8F7D;&#x7F13;&#x6162;&#x3001;&#x4EA4;&#x4E92;&#x5361;&#x987F;&#xFF0C;&#x7528;&#x6237;&#x4F53;&#x9A8C;&#x5C06;&#x975E;&#x5E38;&#x7CDF;&#x7CD5;&#x3002;</p>
<p>&#x5BFC;&#x81F4;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x7684;&#x6839;&#x672C;&#x539F;&#x56E0;&#x5728;&#x4E8E;&#x4E00;&#x6B21;&#x6027;&#x7684;&#x52A0;&#x8F7D;&#x6240;&#x6709;&#x529F;&#x80FD;&#x5BF9;&#x5E94;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x4F46;&#x5176;&#x5B9E;&#x7528;&#x6237;&#x6BCF;&#x4E00;&#x9636;&#x6BB5;&#x53EA;&#x53EF;&#x80FD;&#x4F7F;&#x7528;&#x5176;&#x4E2D;&#x4E00;&#x90E8;&#x5206;&#x529F;&#x80FD;&#x3002;
&#x6240;&#x4EE5;&#x89E3;&#x51B3;&#x4EE5;&#x4E0A;&#x95EE;&#x9898;&#x7684;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x7528;&#x6237;&#x5F53;&#x524D;&#x9700;&#x8981;&#x7528;&#x4EC0;&#x4E48;&#x529F;&#x80FD;&#x5C31;&#x53EA;&#x52A0;&#x8F7D;&#x8FD9;&#x4E2A;&#x529F;&#x80FD;&#x5BF9;&#x5E94;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x6240;&#x8C13;&#x7684;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x3002;</p>
<h2 id="&#x5982;&#x4F55;&#x4F7F;&#x7528;&#x6309;&#x9700;&#x52A0;&#x8F7D;">&#x5982;&#x4F55;&#x4F7F;&#x7528;&#x6309;&#x9700;&#x52A0;&#x8F7D;</h2>
<p>&#x5728;&#x7ED9;&#x5355;&#x9875;&#x5E94;&#x7528;&#x505A;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x4F18;&#x5316;&#x65F6;&#xFF0C;&#x4E00;&#x822C;&#x91C7;&#x7528;&#x4EE5;&#x4E0B;&#x539F;&#x5219;&#xFF1A;</p>
<ul>
<li>&#x628A;&#x6574;&#x4E2A;&#x7F51;&#x7AD9;&#x5212;&#x5206;&#x6210;&#x4E00;&#x4E2A;&#x4E2A;&#x5C0F;&#x529F;&#x80FD;&#xFF0C;&#x518D;&#x6309;&#x7167;&#x6BCF;&#x4E2A;&#x529F;&#x80FD;&#x7684;&#x76F8;&#x5173;&#x7A0B;&#x5EA6;&#x628A;&#x5B83;&#x4EEC;&#x5206;&#x6210;&#x51E0;&#x7C7B;&#x3002;</li>
<li>&#x628A;&#x6BCF;&#x4E00;&#x7C7B;&#x5408;&#x5E76;&#x4E3A;&#x4E00;&#x4E2A; Chunk&#xFF0C;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x5BF9;&#x5E94;&#x7684; Chunk&#x3002;</li>
<li>&#x5BF9;&#x4E8E;&#x7528;&#x6237;&#x9996;&#x6B21;&#x6253;&#x5F00;&#x4F60;&#x7684;&#x7F51;&#x7AD9;&#x65F6;&#x9700;&#x8981;&#x770B;&#x5230;&#x7684;&#x753B;&#x9762;&#x6240;&#x5BF9;&#x5E94;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x4E0D;&#x8981;&#x5BF9;&#x5B83;&#x4EEC;&#x505A;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#xFF0C;&#x800C;&#x662F;&#x653E;&#x5230;&#x6267;&#x884C;&#x5165;&#x53E3;&#x6240;&#x5728;&#x7684; Chunk &#x4E2D;&#xFF0C;&#x4EE5;&#x964D;&#x4F4E;&#x7528;&#x6237;&#x80FD;&#x611F;&#x77E5;&#x7684;&#x7F51;&#x9875;&#x52A0;&#x8F7D;&#x65F6;&#x95F4;&#x3002;</li>
<li>&#x5BF9;&#x4E8E;&#x4E2A;&#x522B;&#x4F9D;&#x8D56;&#x5927;&#x91CF;&#x4EE3;&#x7801;&#x7684;&#x529F;&#x80FD;&#x70B9;&#xFF0C;&#x4F8B;&#x5982;&#x4F9D;&#x8D56; Chart.js &#x53BB;&#x753B;&#x56FE;&#x8868;&#x3001;&#x4F9D;&#x8D56; flv.js &#x53BB;&#x64AD;&#x653E;&#x89C6;&#x9891;&#x7684;&#x529F;&#x80FD;&#x70B9;&#xFF0C;&#x53EF;&#x518D;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x3002;</li>
</ul>
<p>&#x88AB;&#x5206;&#x5272;&#x51FA;&#x53BB;&#x7684;&#x4EE3;&#x7801;&#x7684;&#x52A0;&#x8F7D;&#x9700;&#x8981;&#x4E00;&#x5B9A;&#x7684;&#x65F6;&#x673A;&#x53BB;&#x89E6;&#x53D1;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x5F53;&#x7528;&#x6237;&#x64CD;&#x4F5C;&#x5230;&#x4E86;&#x6216;&#x8005;&#x5373;&#x5C06;&#x64CD;&#x4F5C;&#x5230;&#x5BF9;&#x5E94;&#x7684;&#x529F;&#x80FD;&#x65F6;&#x518D;&#x53BB;&#x52A0;&#x8F7D;&#x5BF9;&#x5E94;&#x7684;&#x4EE3;&#x7801;&#x3002;
&#x88AB;&#x5206;&#x5272;&#x51FA;&#x53BB;&#x7684;&#x4EE3;&#x7801;&#x7684;&#x52A0;&#x8F7D;&#x65F6;&#x673A;&#x9700;&#x8981;&#x5F00;&#x53D1;&#x8005;&#x81EA;&#x5DF1;&#x53BB;&#x6839;&#x636E;&#x7F51;&#x9875;&#x7684;&#x9700;&#x6C42;&#x53BB;&#x8861;&#x91CF;&#x548C;&#x786E;&#x5B9A;&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x88AB;&#x5206;&#x5272;&#x51FA;&#x53BB;&#x8FDB;&#x884C;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x7684;&#x4EE3;&#x7801;&#x5728;&#x52A0;&#x8F7D;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x4E5F;&#x9700;&#x8981;&#x8017;&#x65F6;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x9884;&#x8A00;&#x7528;&#x6237;&#x63A5;&#x4E0B;&#x6765;&#x53EF;&#x80FD;&#x4F1A;&#x8FDB;&#x884C;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x5E76;&#x63D0;&#x524D;&#x52A0;&#x8F7D;&#x597D;&#x5BF9;&#x5E94;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x4ECE;&#x800C;&#x8BA9;&#x7528;&#x6237;&#x611F;&#x77E5;&#x4E0D;&#x5230;&#x7F51;&#x7EDC;&#x52A0;&#x8F7D;&#x65F6;&#x95F4;&#x3002;</p>
<h2 id="&#x7528;-webpack-&#x5B9E;&#x73B0;&#x6309;&#x9700;&#x52A0;&#x8F7D;">&#x7528; Webpack &#x5B9E;&#x73B0;&#x6309;&#x9700;&#x52A0;&#x8F7D;</h2>
<p>Webpack &#x5185;&#x7F6E;&#x4E86;&#x5F3A;&#x5927;&#x7684;&#x5206;&#x5272;&#x4EE3;&#x7801;&#x7684;&#x529F;&#x80FD;&#x53BB;&#x5B9E;&#x73B0;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#xFF0C;&#x5B9E;&#x73B0;&#x8D77;&#x6765;&#x975E;&#x5E38;&#x7B80;&#x5355;&#x3002;</p>
<p>&#x4E3E;&#x4E2A;&#x4F8B;&#x5B50;&#xFF0C;&#x73B0;&#x5728;&#x9700;&#x8981;&#x505A;&#x8FD9;&#x6837;&#x4E00;&#x4E2A;&#x8FDB;&#x884C;&#x4E86;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x4F18;&#x5316;&#x7684;&#x7F51;&#x9875;&#xFF1A;</p>
<ul>
<li>&#x7F51;&#x9875;&#x9996;&#x6B21;&#x52A0;&#x8F7D;&#x65F6;&#x53EA;&#x52A0;&#x8F7D; <code>main.js</code> &#x6587;&#x4EF6;&#xFF0C;&#x7F51;&#x9875;&#x4F1A;&#x5C55;&#x793A;&#x4E00;&#x4E2A;&#x6309;&#x94AE;&#xFF0C;<code>main.js</code> &#x6587;&#x4EF6;&#x4E2D;&#x53EA;&#x5305;&#x542B;&#x76D1;&#x542C;&#x6309;&#x94AE;&#x4E8B;&#x4EF6;&#x548C;&#x52A0;&#x8F7D;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x7684;&#x4EE3;&#x7801;&#x3002;</li>
<li>&#x5F53;&#x6309;&#x94AE;&#x88AB;&#x70B9;&#x51FB;&#x65F6;&#x624D;&#x53BB;&#x52A0;&#x8F7D;&#x88AB;&#x5206;&#x5272;&#x51FA;&#x53BB;&#x7684; <code>show.js</code> &#x6587;&#x4EF6;&#xFF0C;&#x52A0;&#x8F7D;&#x6210;&#x529F;&#x540E;&#x518D;&#x6267;&#x884C; <code>show.js</code> &#x91CC;&#x7684;&#x51FD;&#x6570;&#x3002;</li>
</ul>
<p>&#x5176;&#x4E2D; <code>main.js</code> &#x6587;&#x4EF6;&#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">window</span>.document.getElementById(<span class="hljs-string">&apos;btn&apos;</span>).addEventListener(<span class="hljs-string">&apos;click&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// &#x5F53;&#x6309;&#x94AE;&#x88AB;&#x70B9;&#x51FB;&#x540E;&#x624D;&#x53BB;&#x52A0;&#x8F7D; show.js &#x6587;&#x4EF6;&#xFF0C;&#x6587;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;&#x540E;&#x6267;&#x884C;&#x6587;&#x4EF6;&#x5BFC;&#x51FA;&#x7684;&#x51FD;&#x6570;</span>
  <span class="hljs-keyword">import</span>(<span class="hljs-comment">/* webpackChunkName: &quot;show&quot; */</span> <span class="hljs-string">&apos;./show&apos;</span>).then((show) =&gt; {
    show(<span class="hljs-string">&apos;Webpack&apos;</span>);
  })
});
</code></pre>
<p><code>show.js</code> &#x6587;&#x4EF6;&#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">content</span>) </span>{
  <span class="hljs-built_in">window</span>.alert(<span class="hljs-string">&apos;Hello &apos;</span> + content);
};
</code></pre>
<p>&#x4EE3;&#x7801;&#x4E2D;&#x6700;&#x5173;&#x952E;&#x7684;&#x4E00;&#x53E5;&#x662F; <code>import(/* webpackChunkName: &quot;show&quot; */ &apos;./show&apos;)</code>&#xFF0C;Webpack &#x5185;&#x7F6E;&#x4E86;&#x5BF9; <code>import(*)</code> &#x8BED;&#x53E5;&#x7684;&#x652F;&#x6301;&#xFF0C;&#x5F53; Webpack &#x9047;&#x5230;&#x4E86;&#x7C7B;&#x4F3C;&#x7684;&#x8BED;&#x53E5;&#x65F6;&#x4F1A;&#x8FD9;&#x6837;&#x5904;&#x7406;&#xFF1A;</p>
<ul>
<li>&#x4EE5; <code>./show.js</code> &#x4E3A;&#x5165;&#x53E3;&#x65B0;&#x751F;&#x6210;&#x4E00;&#x4E2A; Chunk&#xFF1B;</li>
<li>&#x5F53;&#x4EE3;&#x7801;&#x6267;&#x884C;&#x5230; <code>import</code> &#x6240;&#x5728;&#x8BED;&#x53E5;&#x65F6;&#x624D;&#x4F1A;&#x53BB;&#x52A0;&#x8F7D;&#x7531; Chunk &#x5BF9;&#x5E94;&#x751F;&#x6210;&#x7684;&#x6587;&#x4EF6;&#x3002;</li>
<li><code>import</code> &#x8FD4;&#x56DE;&#x4E00;&#x4E2A; Promise&#xFF0C;&#x5F53;&#x6587;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;&#x65F6;&#x53EF;&#x4EE5;&#x5728; Promise &#x7684; <code>then</code> &#x65B9;&#x6CD5;&#x4E2D;&#x83B7;&#x53D6;&#x5230; <code>show.js</code> &#x5BFC;&#x51FA;&#x7684;&#x5185;&#x5BB9;&#x3002;</li>
</ul>
<blockquote>
<p>&#x5728;&#x4F7F;&#x7528; <code>import()</code> &#x5206;&#x5272;&#x4EE3;&#x7801;&#x540E;&#xFF0C;&#x4F60;&#x7684;&#x6D4F;&#x89C8;&#x5668;&#x5E76;&#x4E14;&#x8981;&#x652F;&#x6301; <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" target="_blank">Promise API</a> &#x624D;&#x80FD;&#x8BA9;&#x4EE3;&#x7801;&#x6B63;&#x5E38;&#x8FD0;&#x884C;&#xFF0C;
&#x56E0;&#x4E3A; <code>import()</code> &#x8FD4;&#x56DE;&#x4E00;&#x4E2A; Promise&#xFF0C;&#x5B83;&#x4F9D;&#x8D56; Promise&#x3002;&#x5BF9;&#x4E8E;&#x4E0D;&#x539F;&#x751F;&#x652F;&#x6301; Promise &#x7684;&#x6D4F;&#x89C8;&#x5668;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x6CE8;&#x5165; Promise polyfill&#x3002; </p>
<p><code>/* webpackChunkName: &quot;show&quot; */</code> &#x7684;&#x542B;&#x4E49;&#x662F;&#x4E3A;&#x52A8;&#x6001;&#x751F;&#x6210;&#x7684; Chunk &#x8D4B;&#x4E88;&#x4E00;&#x4E2A;&#x540D;&#x79F0;&#xFF0C;&#x4EE5;&#x65B9;&#x4FBF;&#x6211;&#x4EEC;&#x8FFD;&#x8E2A;&#x548C;&#x8C03;&#x8BD5;&#x4EE3;&#x7801;&#x3002;
&#x5982;&#x679C;&#x4E0D;&#x6307;&#x5B9A;&#x52A8;&#x6001;&#x751F;&#x6210;&#x7684; Chunk &#x7684;&#x540D;&#x79F0;&#xFF0C;&#x9ED8;&#x8BA4;&#x540D;&#x79F0;&#x5C06;&#x4F1A;&#x662F; <code>[id].js</code>&#x3002;
<code>/* webpackChunkName: &quot;show&quot; */</code> &#x662F;&#x5728; Webpack3 &#x4E2D;&#x5F15;&#x5165;&#x7684;&#x65B0;&#x7279;&#x6027;&#xFF0C;&#x5728; Webpack3 &#x4E4B;&#x524D;&#x662F;&#x65E0;&#x6CD5;&#x4E3A;&#x52A8;&#x6001;&#x751F;&#x6210;&#x7684; Chunk &#x8D4B;&#x4E88;&#x540D;&#x79F0;&#x7684;&#x3002;</p>
</blockquote>
<p>&#x4E3A;&#x4E86;&#x6B63;&#x786E;&#x7684;&#x8F93;&#x51FA;&#x5728; <code>/* webpackChunkName: &quot;show&quot; */</code> &#x4E2D;&#x914D;&#x7F6E;&#x7684; ChunkName&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x914D;&#x7F6E;&#x4E0B; Webpack&#xFF0C;&#x914D;&#x7F6E;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-comment">// JS &#x6267;&#x884C;&#x5165;&#x53E3;&#x6587;&#x4EF6;</span>
  entry: {
    main: <span class="hljs-string">&apos;./main.js&apos;</span>,
  },
  output: {
    <span class="hljs-comment">// &#x4E3A;&#x4ECE; entry &#x4E2D;&#x914D;&#x7F6E;&#x751F;&#x6210;&#x7684; Chunk &#x914D;&#x7F6E;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x7684;&#x540D;&#x79F0;</span>
    filename: <span class="hljs-string">&apos;[name].js&apos;</span>,
    <span class="hljs-comment">// &#x4E3A;&#x52A8;&#x6001;&#x52A0;&#x8F7D;&#x7684; Chunk &#x914D;&#x7F6E;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x7684;&#x540D;&#x79F0;</span>
    chunkFilename: <span class="hljs-string">&apos;[name].js&apos;</span>,
  }
};
</code></pre>
<p>&#x5176;&#x4E2D;&#x6700;&#x5173;&#x952E;&#x7684;&#x4E00;&#x884C;&#x662F; <code>chunkFilename: &apos;[name].js&apos;,</code>&#xFF0C;&#x5B83;&#x4E13;&#x95E8;&#x6307;&#x5B9A;&#x52A8;&#x6001;&#x751F;&#x6210;&#x7684; Chunk &#x5728;&#x8F93;&#x51FA;&#x65F6;&#x7684;&#x6587;&#x4EF6;&#x540D;&#x79F0;&#x3002;
&#x5982;&#x679C;&#x6CA1;&#x6709;&#x8FD9;&#x884C;&#xFF0C;&#x5206;&#x5272;&#x51FA;&#x7684;&#x4EE3;&#x7801;&#x7684;&#x6587;&#x4EF6;&#x540D;&#x79F0;&#x5C06;&#x4F1A;&#x662F; <code>[id].js</code>&#x3002;
chunkFilename &#x5177;&#x4F53;&#x542B;&#x4E49;&#x89C1;<a href="../2&#x914D;&#x7F6E;/2-2Output.html#chunkFilename">2-2 &#x914D;&#x7F6E;-Output</a>&#x3002;</p>
<blockquote>
<p>&#x672C;&#x5B9E;&#x4F8B;<a href="http://webpack.wuhaolin.cn/4-12&#x5206;&#x5272;&#x4EE3;&#x7801;&#x6309;&#x9700;&#x52A0;&#x8F7D;.zip" target="_blank">&#x63D0;&#x4F9B;&#x9879;&#x76EE;&#x5B8C;&#x6574;&#x4EE3;&#x7801;</a></p>
</blockquote>
<h2 id="&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x4E0E;-reactrouter">&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x4E0E; ReactRouter</h2>
<p>&#x5728;&#x5B9E;&#x6218;&#x4E2D;&#xFF0C;&#x4E0D;&#x53EF;&#x80FD;&#x4F1A;&#x6709;&#x4E0A;&#x9762;&#x90A3;&#x4E48;&#x7B80;&#x5355;&#x7684;&#x573A;&#x666F;&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x4E3E;&#x4E00;&#x4E2A;&#x5B9E;&#x6218;&#x4E2D;&#x7684;&#x4F8B;&#x5B50;&#xFF1A;&#x5BF9;&#x91C7;&#x7528;&#x4E86; <a href="https://reacttraining.com/react-router/web" target="_blank">ReactRouter</a> &#x7684;&#x5E94;&#x7528;&#x8FDB;&#x884C;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x4F18;&#x5316;&#x3002;
&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x7531;&#x4E00;&#x4E2A;&#x5355;&#x9875;&#x5E94;&#x7528;&#x6784;&#x6210;&#xFF0C;&#x8FD9;&#x4E2A;&#x5355;&#x9875;&#x5E94;&#x7528;&#x7531;&#x4E24;&#x4E2A;&#x5B50;&#x9875;&#x9762;&#x6784;&#x6210;&#xFF0C;&#x901A;&#x8FC7; ReactRouter &#x5728;&#x4E24;&#x4E2A;&#x5B50;&#x9875;&#x9762;&#x4E4B;&#x95F4;&#x5207;&#x6362;&#x548C;&#x7BA1;&#x7406;&#x8DEF;&#x7531;&#x3002;</p>
<p>&#x8FD9;&#x4E2A;&#x5355;&#x9875;&#x5E94;&#x7528;&#x7684;&#x5165;&#x53E3;&#x6587;&#x4EF6; <code>main.js</code> &#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> React, {PureComponent, createElement} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react&apos;</span>;
<span class="hljs-keyword">import</span> {render} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react-dom&apos;</span>;
<span class="hljs-keyword">import</span> {HashRouter, Route, Link} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;react-router-dom&apos;</span>;
<span class="hljs-keyword">import</span> PageHome <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;./pages/home&apos;</span>;

<span class="hljs-comment">/**
 * &#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7EC4;&#x4EF6;
 * @param load &#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x51FD;&#x6570;&#xFF0C;load &#x51FD;&#x6570;&#x4F1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A; Promise&#xFF0C;&#x5728;&#x6587;&#x4EF6;&#x52A0;&#x8F7D;&#x5B8C;&#x6210;&#x65F6; resolve
 * @returns {AsyncComponent} &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x9AD8;&#x9636;&#x7EC4;&#x4EF6;&#x7528;&#x4E8E;&#x5C01;&#x88C5;&#x9700;&#x8981;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684;&#x7EC4;&#x4EF6;
 */</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getAsyncComponent</span>(<span class="hljs-params">load</span>) </span>{
  <span class="hljs-keyword">return</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AsyncComponent</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">PureComponent</span> </span>{

    componentDidMount() {
      <span class="hljs-comment">// &#x5728;&#x9AD8;&#x9636;&#x7EC4;&#x4EF6; DidMount &#x65F6;&#x624D;&#x53BB;&#x6267;&#x884C;&#x7F51;&#x7EDC;&#x52A0;&#x8F7D;&#x6B65;&#x9AA4;</span>
      load().then(({<span class="hljs-keyword">default</span>: component}) =&gt; {
        <span class="hljs-comment">// &#x4EE3;&#x7801;&#x52A0;&#x8F7D;&#x6210;&#x529F;&#xFF0C;&#x83B7;&#x53D6;&#x5230;&#x4E86;&#x4EE3;&#x7801;&#x5BFC;&#x51FA;&#x7684;&#x503C;&#xFF0C;&#x8C03;&#x7528; setState &#x901A;&#x77E5;&#x9AD8;&#x9636;&#x7EC4;&#x4EF6;&#x91CD;&#x65B0;&#x6E32;&#x67D3;&#x5B50;&#x7EC4;&#x4EF6;</span>
        <span class="hljs-keyword">this</span>.setState({
          component,
        })
      });
    }

    render() {
      <span class="hljs-keyword">const</span> {component} = <span class="hljs-keyword">this</span>.state || {};
      <span class="hljs-comment">// component &#x662F; React.Component &#x7C7B;&#x578B;&#xFF0C;&#x9700;&#x8981;&#x901A;&#x8FC7; React.createElement &#x751F;&#x4EA7;&#x4E00;&#x4E2A;&#x7EC4;&#x4EF6;&#x5B9E;&#x4F8B;</span>
      <span class="hljs-keyword">return</span> component ? createElement(component) : <span class="hljs-literal">null</span>;
    }
  }
}

<span class="hljs-comment">// &#x6839;&#x7EC4;&#x4EF6;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    &lt;HashRouter&gt;
      &lt;div&gt;
        &lt;nav&gt;
          &lt;Link to=&apos;/&apos;&gt;Home&lt;/Link&gt; | &lt;Link to=&apos;/about&apos;&gt;About&lt;/Link&gt; | &lt;Link to=&apos;/login&apos;&gt;Login&lt;/Link&gt;
        &lt;/nav&gt;
        &lt;hr/&gt;
        &lt;Route exact path=&apos;/&apos; component={PageHome}/&gt;
        &lt;Route path=&apos;/about&apos; component={getAsyncComponent(
          // &#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x51FD;&#x6570;&#xFF0C;&#x5F02;&#x6B65;&#x5730;&#x52A0;&#x8F7D; PageAbout &#x7EC4;&#x4EF6;
          () =&gt; import(/* webpackChunkName: &apos;page-about&apos; */&apos;./pages/about&apos;)
        )}
        /&gt;
        &lt;Route path=&apos;/login&apos; component={getAsyncComponent(
          // &#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x51FD;&#x6570;&#xFF0C;&#x5F02;&#x6B65;&#x5730;&#x52A0;&#x8F7D; PageAbout &#x7EC4;&#x4EF6;
          () =&gt; import(/* webpackChunkName: &apos;page-login&apos; */&apos;./pages/login&apos;)
        )}
        /&gt;
      &lt;/div&gt;
    &lt;/HashRouter&gt;
  )
}

// &#x6E32;&#x67D3;&#x6839;&#x7EC4;&#x4EF6;
render(&lt;App/&gt;, window.document.getElementById(&apos;app&apos;));
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#x4E2D;&#x6700;&#x5173;&#x952E;&#x7684;&#x90E8;&#x5206;&#x662F; <code>getAsyncComponent</code> &#x51FD;&#x6570;&#xFF0C;&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x662F;&#x914D;&#x5408; ReactRouter &#x53BB;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x7EC4;&#x4EF6;&#xFF0C;&#x5177;&#x4F53;&#x542B;&#x4E49;&#x8BF7;&#x770B;&#x4EE3;&#x7801;&#x4E2D;&#x7684;&#x6CE8;&#x91CA;&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x4EE5;&#x4E0A;&#x6E90;&#x7801;&#x9700;&#x8981;&#x901A;&#x8FC7; Babel &#x53BB;&#x8F6C;&#x6362;&#x540E;&#x624D;&#x80FD;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x6B63;&#x5E38;&#x8FD0;&#x884C;&#xFF0C;&#x9700;&#x8981;&#x5728; Webpack &#x4E2D;&#x914D;&#x7F6E;&#x597D;&#x5BF9;&#x5E94;&#x7684; babel-loader&#xFF0C;&#x6E90;&#x7801;&#x5148;&#x4EA4;&#x7ED9; babel-loader &#x5904;&#x7406;&#x540E;&#x518D;&#x4EA4;&#x7ED9; Webpack &#x53BB;&#x5904;&#x7406;&#x5176;&#x4E2D;&#x7684; <code>import(*)</code> &#x8BED;&#x53E5;&#x3002;
&#x4F46;&#x8FD9;&#x6837;&#x505A;&#x540E;&#x4F60;&#x5F88;&#x5FEB;&#x4F1A;&#x53D1;&#x73B0;&#x4E00;&#x4E2A;&#x95EE;&#x9898;&#xFF1A;Babel &#x62A5;&#x51FA;&#x9519;&#x8BEF;&#x8BF4;&#x4E0D;&#x8BA4;&#x8BC6; <code>import(*)</code> &#x8BED;&#x6CD5;&#x3002;
&#x5BFC;&#x81F4;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x7684;&#x539F;&#x56E0;&#x662F; <code>import(*)</code> &#x8BED;&#x6CD5;&#x8FD8;&#x6CA1;&#x6709;&#x88AB;&#x52A0;&#x5165;&#x5230;&#x5728; <a href="../3&#x5B9E;&#x6218;/3-1&#x4F7F;&#x7528;ES6&#x8BED;&#x8A00;.html#Presets">3-1&#x4F7F;&#x7528;ES6&#x8BED;&#x8A00;</a>&#x4E2D;&#x63D0;&#x5230;&#x7684; ECMAScript &#x6807;&#x51C6;&#x4E2D;&#x53BB;&#xFF0C;
&#x4E3A;&#x6B64;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5B89;&#x88C5;&#x4E00;&#x4E2A; Babel &#x63D2;&#x4EF6; <code>babel-plugin-syntax-dynamic-import</code>&#xFF0C;&#x5E76;&#x4E14;&#x5C06;&#x5176;&#x52A0;&#x5165;&#x5230; <code>.babelrc</code> &#x4E2D;&#x53BB;&#xFF1A;</p>
<pre><code class="lang-json">{
  <span class="hljs-string">&quot;presets&quot;</span>: [
    <span class="hljs-string">&quot;env&quot;</span>,
    <span class="hljs-string">&quot;react&quot;</span>
  ],
  <span class="hljs-string">&quot;plugins&quot;</span>: [
    <span class="hljs-string">&quot;syntax-dynamic-import&quot;</span>
  ]
}
</code></pre>
<p>&#x6267;&#x884C; Webpack &#x6784;&#x5EFA;&#x540E;&#xFF0C;&#x4F60;&#x4F1A;&#x53D1;&#x73B0;&#x8F93;&#x51FA;&#x4E86;&#x4E09;&#x4E2A;&#x6587;&#x4EF6;&#xFF1A;</p>
<ul>
<li><code>main.js</code>&#xFF1A;&#x6267;&#x884C;&#x5165;&#x53E3;&#x6240;&#x5728;&#x7684;&#x4EE3;&#x7801;&#x5757;&#xFF0C;&#x540C;&#x65F6;&#x8FD8;&#x5305;&#x62EC; PageHome &#x6240;&#x9700;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x56E0;&#x4E3A;&#x7528;&#x6237;&#x9996;&#x6B21;&#x6253;&#x5F00;&#x7F51;&#x9875;&#x65F6;&#x5C31;&#x9700;&#x8981;&#x770B;&#x5230; PageHome &#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#xFF0C;&#x4EE5;&#x964D;&#x4F4E;&#x7528;&#x6237;&#x80FD;&#x611F;&#x77E5;&#x5230;&#x7684;&#x52A0;&#x8F7D;&#x65F6;&#x95F4;&#xFF1B;</li>
<li><code>page-about.js</code>&#xFF1A;&#x5F53;&#x7528;&#x6237;&#x8BBF;&#x95EE; <code>/about</code> &#x65F6;&#x624D;&#x4F1A;&#x52A0;&#x8F7D;&#x7684;&#x4EE3;&#x7801;&#x5757;&#xFF1B;</li>
<li><code>page-login.js</code>&#xFF1A;&#x5F53;&#x7528;&#x6237;&#x8BBF;&#x95EE; <code>/login</code> &#x65F6;&#x624D;&#x4F1A;&#x52A0;&#x8F7D;&#x7684;&#x4EE3;&#x7801;&#x5757;&#x3002;</li>
</ul>
<p>&#x540C;&#x65F6;&#x4F60;&#x8FD8;&#x4F1A;&#x53D1;&#x73B0; <code>page-about.js</code> &#x548C; <code>page-login.js</code> &#x8FD9;&#x4E24;&#x4E2A;&#x6587;&#x4EF6;&#x5728;&#x9996;&#x9875;&#x662F;&#x4E0D;&#x4F1A;&#x52A0;&#x8F7D;&#x7684;&#xFF0C;&#x800C;&#x662F;&#x4F1A;&#x5F53;&#x4F60;&#x5207;&#x6362;&#x5230;&#x4E86;&#x5BF9;&#x5E94;&#x7684;&#x5B50;&#x9875;&#x9762;&#x540E;&#x6587;&#x4EF6;&#x624D;&#x4F1A;&#x5F00;&#x59CB;&#x52A0;&#x8F7D;&#x3002;</p>
<blockquote>
<p>&#x672C;&#x5B9E;&#x4F8B;<a href="http://webpack.wuhaolin.cn/4-12&#x5206;&#x5272;&#x4EE3;&#x7801;&#x6309;&#x9700;&#x52A0;&#x8F7D;ReactRouter.zip" target="_blank">&#x63D0;&#x4F9B;&#x9879;&#x76EE;&#x5B8C;&#x6574;&#x4EE3;&#x7801;</a></p>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="4-11提取公共代码.html" class="navigation navigation-prev " aria-label="Previous page: 4-11 提取公共代码">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="4-13使用Prepack.html" class="navigation navigation-next " aria-label="Next page: 4-13 使用 Prepack">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"4-12 按需加载","level":"1.6.12","depth":2,"next":{"title":"4-13 使用 Prepack","level":"1.6.13","depth":2,"path":"4优化/4-13使用Prepack.md","ref":"4优化/4-13使用Prepack.md","articles":[]},"previous":{"title":"4-11 提取公共代码","level":"1.6.11","depth":2,"path":"4优化/4-11提取公共代码.md","ref":"4优化/4-11提取公共代码.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github-buttons","ga","modal","adsense"],"root":"./docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"search":{},"adsense":{"client":"ca-pub-9697944574373240","slot":"9319793387","format":"auto","element":".page-inner section","position":"top"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"modal":{"closable":true,"excludeUrls":["\\?q=.+$","index.html","前言.html","\\/$","1-.+","2-2Output","3-1使用ES6语言","3-2使用TypeScript语言","3-4使用SCSS语言.html","3-5使用PostCSS.html","3-6使用React框架","3-7使用Vue框架","3-8使用Angular2框架","3-9为单页应用生成HTML","3-10管理多个单页应用","3-17通过Node.jsAPI启动Webpack","3-20加载SVG"],"html":"<div style='text-align: center'><a href='http://union-click.jd.com/jdc?d=1AMcaz'><img src='http://p0.meituan.net/scarlett/df16c51ffb95186df6f75d8c0e22b965842464.png' width='306px' height='411px'><a/> <h2><a target='_blank' href='http://union-click.jd.com/jdc?d=1AMcaz'>购买本书纸质版</a></h2></div>"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"github-buttons":{"buttons":[{"user":"gwuhaolin","type":"follow","size":"small","width":"150"},{"user":"gwuhaolin","repo":"dive-into-webpack","type":"star","size":"small"}]},"ga":{"configuration":"auto","token":"UA-54964850-3"},"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"吴浩麟","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"9787121331725","variables":{},"title":"深入浅出 Webpack","language":"zh-hans","gitbook":"*","description":"本书按照入门、配置、实战、优化、原理的路线层层深入，涵盖了 Webpack 的方方面面。对于小白，本书可以作为 Webpack 入门教程，对于老手，本书可以进一步加深你对 Webpack 的理解。"},"file":{"path":"4优化/4-12按需加载.md","mtime":"2018-04-24T03:12:22.868Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-12-22T08:51:47.376Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-ga/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-modal/index.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-adsense/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

